/*
 * Copyright (c) novafaen design 2009 
 */
package tentaflykt.gui;

import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import javax.swing.JFrame;

/**
 * Abstract window class.
 * @author Kristoffer Nilsson
 */
public abstract class AbstractWindow 
extends JFrame {
  private static final long serialVersionUID = 5708823730929047198L;
  
  /**
   * Default constructor.
   * @param title The window title
   */
  public AbstractWindow(String title) {
    super(title);
    
    // default close action, exit program
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
    // add window actions.
    addWindowListener(new WindowListener() {
      @Override
      public void windowOpened(WindowEvent we) {
        onOpen();
      }
      
      @Override
      public void windowClosing(WindowEvent we) {
        onExit();
      }
      
      @Override
      public void windowClosed(WindowEvent we) {
        onExit(); // called by dispose()
      }
      
      @Override
      public void windowIconified(WindowEvent we) {
        // no implementation
      }
      
      @Override
      public void windowDeiconified(WindowEvent we) {
        // no implementation
      }
      
      @Override
      public void windowDeactivated(WindowEvent we) {
        // no implementation
      }
      
      @Override
      public void windowActivated(WindowEvent we) {
        // no implementation
      }
    });
  }

  /**
   * Called upon window open action, when made visible.
   */
  public abstract void onOpen();
  
  /**
   * Called upon window close action, when invoked by user from
   * the program.
   */
  public abstract void onExit();
  
  /**
   * Try to exit program in a controlled manner.
   */
  public abstract void tryExit();
}
